home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / SSCANF.C < prev    next >
Text File  |  1986-05-18  |  2KB  |  54 lines

  1. /* 1.1  01-08-86                        (sscanf.c)
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1985        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10. #include "stdio.h"
  11.  
  12. /*----------------------------------------------------------------------*/
  13.  
  14. LOCAL STRING     scanstr;
  15. LOCAL BOOL     NOT_EOL;
  16.  
  17. /************************************************************************/
  18.  
  19. sscanf(s, fmt, arg)    /* Read string s using format fmt, and deposit
  20.                information into arguments in arg list. Return
  21.                count of items read.                */
  22. /*----------------------------------------------------------------------*/
  23. STRING s, fmt;
  24. int *arg;
  25. {
  26.     int sgetc(), unformat();
  27.  
  28.     scanstr = s;
  29.     NOT_EOL = TRUE;
  30.     return unformat(sgetc, fmt, &arg);
  31. }
  32.  
  33. /************************************************************************/
  34.     LOCAL
  35. sgetc(forward)        /* Return a character from the LOCAL scanstr.
  36.                If forward is TRUE, get next character and
  37.                advance; else, back up and get one unless the
  38.                end has been reached. Return EOF if so.    */
  39. /*----------------------------------------------------------------------*/
  40. BOOL forward;
  41. {
  42.     if (forward)
  43.     {    if (*scanstr)
  44.             return *scanstr++ & 0xff;
  45.  
  46.         else
  47.             NOT_EOL = FALSE;
  48.     }
  49.     else if (NOT_EOL)
  50.         return *--scanstr & 0xff;
  51.  
  52.     return EOF;
  53. }
  54.